package com.seaking.controller;

import com.seaking.pojo.Data;
import com.seaking.pojo.Department;
import com.seaking.pojo.Platform;
import com.seaking.pojo.School;
import com.seaking.service.DataService;
import com.seaking.service.DepartmentService;
import com.seaking.service.PlatformService;
import com.seaking.service.SchoolService;
import com.seaking.util.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * Created by wchha on 10/24 0024.
 */
@Controller
public class IndexController {

    @Autowired
    private SchoolService schoolService;

    @Autowired
    private DepartmentService departmentService;

    @Autowired
    private DataService dataService;

    @Autowired
    PlatformService platformService;


    @RequestMapping("/index")
    public String index(Model model, Data data1, Page page, HttpSession session) {

        Long counts = dataService.getCount();
        session.setAttribute("counts",counts);
        List<School> schoolList = schoolService.getSchool();
        List<Department> department = departmentService.getDepartment();
        List<Platform> platform = platformService.getPlatform();
        List list = schoolService.leftSchool();
        List<Data> data = null;
        if (data1.getPlatform() != null || data1.getSchool() != null || data1.getTime() != null || data1.getDepartment() != null) {
            data = dataService.getChose(data1, page);
        } else {
            data = dataService.getAll(page);
        }
        if(data != null){
            model.addAttribute("datas", data);
        }else{
            model.addAttribute("msg", "暂无数据！");
        }
        model.addAttribute("page", page);
        model.addAttribute("schools", schoolList);
        model.addAttribute("platforms", platform);
        model.addAttribute("lists", list);
        model.addAttribute("data", data1);
        model.addAttribute("departments", department);
        return "index";
    }
}
